package cn.shierblog.spider_zhiping;

import org.openqa.selenium.By;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import java.util.concurrent.TimeUnit;

public class BaiduSpider extends AbstractSpider {


    public BaiduSpider(String url) {
        super(url);
    }

    @Override
    public void spider() {
        try {

            WebElement input = driver.findElement(By.cssSelector("#kw"));
            WebElement submit = driver.findElement(By.cssSelector("#su"));
            input.clear();
            input.sendKeys("供应链");
            Thread.sleep(1);
            driver.executeScript("arguments[0].click();", submit);

            driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
            TimeUnit.SECONDS.sleep(2);
            String pageSource = driver.getPageSource();
            //source
            System.out.println(pageSource);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            driver.close();
        }
    }


    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
        new BaiduSpider( "https://www.baidu.com/s?wd=%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95").craw();
    }
}
